<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/7/3
 * Time: 9:13
 */

namespace app\service;


use think\Db;

class PrizeService
{
    /**
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @context 获取卡券列表
     */
    static function voucher_list()
    {
        $list=Db::table('voucher')->field("id,title,price")->order("price")->select();
        return array("data"=>$list);
    }

    /**
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @context 大转轮奖品获取卡券
     */
    static function prizeVoucher()
    {
        $list=self::voucher_list()['data'];
        if(!empty($list)){
            $str="<div class=\"mainContent\">";
            foreach($list as $k=>$v){
                $str.="<div class=\"item-list\" onclick='chooseVoucher(\"{$v['id']}\",\"{$v['title']}\",\"{$v['price']}\")'>
                            <div class=\"item-title\">{$v['title']}</div>
                            <div class=\"item-value\">￥{$v['price']}</div>
                        </div>";
            }
            $str.="</div>";
            return array("status"=>true,'data'=>$str);
        }else{
            return array("status"=>false,"msg"=>"暂无可用卡券");
        }
    }
}